<?php
namespace app\index\controller;
use Workerman\Worker;
use GatewayWorker\Register;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;

class Run{
    
//控制器无需继承Controller
  /**
     * 构造函数
     * @access public
     */
    public function __construct()    {
        //初始化register
        new Register('text://0.0.0.0:2340');
        self::BusinessWorker();
        self::Gateway();
        //运行所有Worker;
       Worker::runAll();
    }
    private static function BusinessWorker(){
        //初始化各个GatewayWorker
     //初始化 bussinessWorker 进程
        $worker = new BusinessWorker();
        $worker->name = 'YourAppBusinessWorker';
        $worker->count = 4;
        $worker->registerAddress = '127.0.0.1:2340'; #内部通讯的
        //设置处理业务的类,此处制定Events的命名空间
        $worker->eventHandler = \app\index\controller\Gatewayworker\Events::class;
    }
    static private function Gateway(){
        // 初始化 gateway 进程
        $gateway = new Gateway("websocket://0.0.0.0:2345"); 
        $gateway->name = 'YourAppGateway';
        $gateway->count = 4;#开启线程数
        $gateway->lanIp = '127.0.0.1';
        $gateway->startPort = 2900;
        $gateway->registerAddress = '127.0.0.1:2340';
        $gateway->pingInterval = 10; #
        //心跳
        $gateway->pingNotResponseLimit = 5; #轮询5次没有回复就关闭连接，并判断为该用户已经下线
        $gateway->pingData = '{"type":"ping"}';
    }

}